package com.bst.common.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.*;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bst.common.vo.WeatherVO;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.apache.ibatis.reflection.wrapper.BaseWrapper;

public class WeatherUtil {

    public static JSONArray queryWeather(String month) throws IOException {

        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        Request request = new Request.Builder()
                .url("http://gfeljm.tianqiapi.com/free/history?appid=43656176&appsecret=I42og6Lm&cityid=101280606&year="+month.substring(0,4)+"&month="+Integer.parseInt(month.substring(5,7)))
                .method("GET", null)
                .build();
        Response response = client.newCall(request).execute();
        String dataDes = response.body().string();
        JSONObject jsonObject = JSONObject.parseObject(dataDes);
        JSONArray arr = jsonObject.getJSONArray("list");
        return arr;
    }


    public static void main(String[] args) throws IOException {

        System.out.println(queryWeather("2024-01"));
    }
}
